const { ccclass, property } = cc._decorator;

@ccclass
export default class FlipTween extends cc.Component {
    @property()
    duration = 0;

    onLoad() { }

    start() { }

    flip(e, t, a, o) {
        return new Promise(function (resolve) {
            var tween = cc.tween;
            var halfDuration = t / 2;
            var scale = e.scale;
            var skewY = scale > 0 ? 20 : -20;

            tween(e)
                .parallel(
                    tween().to(halfDuration, {
                        scaleX: 0
                    }, {
                        easing: "quadIn"
                    }),
                    tween().to(halfDuration, {
                        skewY: -skewY
                    }, {
                        easing: "quadOut"
                    })
                )
                .call(function () {
                    if (a) {
                        a();
                    }
                })
                .parallel(
                    tween().to(halfDuration, {
                        scaleX: -scale
                    }, {
                        easing: "quadOut"
                    }),
                    tween().to(halfDuration, {
                        skewY: 0
                    }, {
                        easing: "quadIn"
                    })
                )
                .call(function () {
                    if (o) {
                        o();
                    }
                    resolve(true);
                })
                .start();
        });
    }
}